package com.hzhr.iot.device.dao;

import com.hzhr.iot.device.dao.mapper.custom.OptionsEntityCustomMapper;
import com.hzhr.iot.device.dao.mapper.generator.OptionsEntityMapper;
import com.hzhr.iot.device.entity.OptionsEntity;
import com.hzhr.iot.device.entity.ext.OptionsEntityExt;
import com.hzhr.iot.device.queryModel.custom.OptionsCustomQueryModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class OptionsDao {
    @Autowired
    OptionsEntityMapper optionsEntityMapper;
    @Autowired
    OptionsEntityCustomMapper optionsEntityCustomMapper;

    public int insert(OptionsEntity record) {
        if (record == null) return 0;
        int changeCount = optionsEntityMapper.insert(record);
        return changeCount;
    }

    public int delete(OptionsCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int changeCount = optionsEntityCustomMapper.delete(queryModel);
        return changeCount;
    }

    public int update(OptionsEntity record) {
        if (record == null) return 0;
        int changeCount = optionsEntityMapper.updateByPrimaryKey(record);
        return changeCount;
    }

    public int updateProps(OptionsCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int changeCount = optionsEntityCustomMapper.updateProps(queryModel);
        return changeCount;
    }

    public OptionsEntityExt selectEntity(OptionsCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<OptionsEntityExt> extList = optionsEntityCustomMapper.selectExt(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<OptionsEntity> selectEntityList(OptionsCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<OptionsEntityExt> extList = optionsEntityCustomMapper.selectExt(queryModel);
        if (extList == null) return null;
        List<OptionsEntity> entityList = new ArrayList<>();
        for (OptionsEntityExt ext : extList) {
            entityList.add(ext);
        }
        return entityList;
    }
    public OptionsEntityExt selectExt(OptionsCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<OptionsEntityExt> extList = optionsEntityCustomMapper.selectExt(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<OptionsEntityExt> selectExtList(OptionsCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<OptionsEntityExt> extList = optionsEntityCustomMapper.selectExt(queryModel);
        return extList;
    }

    public int selectCount(OptionsCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int count = optionsEntityCustomMapper.selectCount(queryModel);
        return count;
    }
}
